﻿Imports System.Data.SqlClient

Public Class frmRIngresos
    Dim Bitacora As New clsActividad
    Dim Usuario As New clsUsuarioPrincipal

    Private Sub frmRIngresos_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Bitacora.RegistraActividad("Cerró al Reporte de Ingresos")
        Usuario.Ubicacion("Módulo de Liquidación")
    End Sub

    Private Sub frmRIngresos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip1.Cursor = Cursors.Hand
        ToolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System

        datFecha1.Value = Now()
        datFecha2.Value = Now()

        RadioButton1.Checked = True

        Bitacora.RegistraActividad("Ingresó al Reporte de Ingresos")
        Usuario.Ubicacion("Reporte de Ingresos")
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        Close()

    End Sub
    Sub todos()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook
        Dim rng As Integer
        rng = 5

        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim strFecha1 As String = Format(Me.datFecha1.Value.Year, "0000") & Format(Me.datFecha1.Value.Month, "00") & Format(Me.datFecha1.Value.Day, "00")
        Dim strFecha2 As String = Format(Me.datFecha2.Value.Year, "0000") & Format(Me.datFecha2.Value.Month, "00") & Format(Me.datFecha2.Value.Day, "00")
        '--------
        Dim cnconn As New SqlConnection
        cnconn.ConnectionString = CitraConnection
        Dim strSql As String = ""
        cnconn.Open()
        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnconn

        strSql = " SELECT IdRuta,NombreRuta,NoEconomico,SUM(General) as general,SUM(Preferencial) as preferencial,SUM(TotalBoletos) as boletos,SUM(Liquidacion) as total,SUM(Vueltas) as vueltas " & _
                 " FROM Liquidacion" & _
                 " WHERE convert(varchar,fecha,101)>='" & strFecha1 & "'" & _
                 " AND convert(varchar,fecha,101)<='" & strFecha2 & "'" & _
                 " GROUP BY NoEconomico" & _
                 " ORDER BY IdRuta,NombreRuta,NoEconomico"

        cmdBuscar.CommandText = strSql
        Dim rdBuscar As SqlDataReader
        rdBuscar = cmdBuscar.ExecuteReader
        Dim strFecha As String = ""
        Dim strCamion As String = "?"
        Dim strFechaMov As String = ""
        Dim PrecioP As Double = 3.7
        Dim PrecioG As Double = 6.3

        Dim totalUP As Double = 0
        Dim totalUG As Double = 0
        Dim totalUB As Double = 0
        Dim totalIP As Double = 0
        Dim totalIG As Double = 0
        Dim totalIB As Double = 0
        Dim TotalV As Double = 0
        Dim TotalK As Double = 0


        Dim totalUPG As Double = 0
        Dim totalUGG As Double = 0
        Dim totalUBG As Double = 0
        Dim totalIPG As Double = 0
        Dim totalIGG As Double = 0
        Dim totalIBG As Double = 0
        Dim TotalVG As Double = 0
        Dim TotalKG As Double = 0
        Dim Encabezado As Integer = 0



        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 12
        wb.SHEETS(1).columns(4).columnwidth = 12
        wb.SHEETS(1).columns(5).columnwidth = 12
        wb.SHEETS(1).columns(6).columnwidth = 12
        wb.SHEETS(1).columns(7).columnwidth = 12
        wb.SHEETS(1).columns(8).columnwidth = 12
        wb.SHEETS(1).columns(9).columnwidth = 12
        wb.SHEETS(1).columns(10).columnwidth = 12
        wb.sheets(1).columns(11).columnwidth = 12
        wb.sheets(1).columns(12).columnwidth = 12
        wb.sheets(1).columns(13).columnwidth = 12
        wb.sheets(1).columns(14).columnwidth = 12
        wb.sheets(1).columns(15).columnwidth = 12
        wb.sheets(1).columns(16).columnwidth = 12

        wb.SHEETS(1).columns(3).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(4).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(5).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(6).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(7).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(8).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(9).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(10).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(11).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(12).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(13).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(14).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(15).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(16).NumberFormat = "#,##0.00"

        Do While rdBuscar.Read()
            If strCamion <> rdBuscar("NombreRuta").ToString.Trim Then
                If strCamion <> "?" Then
                    For j = 2 To 16
                        wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

                    Next
                    wb.SHEETS(1).cells(rng, 2).value = "Totales"
                    wb.SHEETS(1).cells(rng, 3).value = totalUG
                    wb.SHEETS(1).cells(rng, 4).value = totalIG
                    wb.SHEETS(1).cells(rng, 5).value = totalUP
                    wb.SHEETS(1).cells(rng, 6).value = totalIP
                    wb.SHEETS(1).cells(rng, 7).value = totalUB
                    wb.SHEETS(1).cells(rng, 8).value = totalIB
                    wb.SHEETS(1).cells(rng, 9).value = totalUG + totalUP + totalUB
                    wb.SHEETS(1).cells(rng, 10).value = totalIG + totalIP + totalIB
                    wb.SHEETS(1).cells(rng, 11).value = TotalV
                    wb.SHEETS(1).cells(rng, 12).value = TotalK
                    wb.SHEETS(1).cells(rng, 13).value = wb.SHEETS(1).cells(rng, 8).value / TotalV
                    wb.SHEETS(1).cells(rng, 14).value = wb.SHEETS(1).cells(rng, 9).value / TotalV
                    wb.SHEETS(1).cells(rng, 15).value = wb.SHEETS(1).cells(rng, 8).value / TotalK
                    wb.SHEETS(1).cells(rng, 16).value = wb.SHEETS(1).cells(rng, 9).value / TotalK

                    For i = Encabezado To rng - 1
                        wb.SHEETS(1).cells(i, 13).value = wb.SHEETS(1).cells(i, 9).value / wb.SHEETS(1).cells(i, 11).value
                        wb.SHEETS(1).cells(i, 14).value = wb.SHEETS(1).cells(i, 10).value / wb.SHEETS(1).cells(i, 11).value
                        wb.SHEETS(1).cells(i, 15).value = wb.SHEETS(1).cells(i, 9).value / wb.SHEETS(1).cells(i, 12).value
                        wb.SHEETS(1).cells(i, 16).value = wb.SHEETS(1).cells(i, 10).value / wb.SHEETS(1).cells(i, 12).value
                    Next

                    For i = 2 To 16
                        wb.SHEETS(1).cells(rng, i).font.italic = True
                    Next

                    totalUP = 0
                    totalUG = 0
                    totalUB = 0
                    totalIP = 0
                    totalIG = 0
                    totalIB = 0
                    TotalV = 0
                    TotalK = 0
                    rng = rng + 2 ' Separa entre ruta
                End If
                For j = 2 To 16
                    wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

                Next
                wb.SHEETS(1).cells(rng, 2).value = rdBuscar("Nombre").ToString.Trim
                wb.SHEETS(1).cells(rng, 2).font.size = 12
                wb.SHEETS(1).cells(rng, 2).font.bold = -1
                rng = rng + 1
                For j = 2 To 16
                    wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

                Next
                wb.SHEETS(1).cells(rng, 2).value = "Autobus"
                wb.SHEETS(1).cells(rng, 3).value = "Pagobus General en Unidades"
                wb.SHEETS(1).cells(rng, 4).value = "Pagobus Preferencial en unidades"
                wb.SHEETS(1).cells(rng, 5).value = "Boletos en Unidades"
                wb.SHEETS(1).cells(rng, 6).value = "Pagobus General en Importes"
                wb.SHEETS(1).cells(rng, 7).value = "Pagobus Preferencial en Importes"
                wb.SHEETS(1).cells(rng, 8).value = "Boletos en Importes"
                wb.SHEETS(1).cells(rng, 9).value = "Movilidad en Unidades"
                wb.SHEETS(1).cells(rng, 10).value = "Movilidad en Pesos"
                wb.SHEETS(1).cells(rng, 11).value = "Vueltas"
                wb.SHEETS(1).cells(rng, 12).value = "Kilometros"
                wb.SHEETS(1).cells(rng, 13).value = "Promedio Movilidad por Vuelta"
                wb.SHEETS(1).cells(rng, 14).value = "Promedio Ingresos por Vuelta"
                wb.SHEETS(1).cells(rng, 15).value = "Promedio Movilidad por KM"
                wb.SHEETS(1).cells(rng, 16).value = "Promedio Ingresos por KM"

                For i = 2 To 16
                    wb.SHEETS(1).cells(rng, i).font.bold = True
                    wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
                    wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
                    wb.SHEETS(1).CELLS(rng, i).WrapText = True
                    wb.SHEETS(1).CELLS(rng, i).Orientation = 0
                    wb.SHEETS(1).CELLS(rng, i).AddIndent = False
                    wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
                    wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
                    wb.SHEETS(1).CELLS(rng, i).MergeCells = False
                    wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
                Next
                rng = rng + 1
                Encabezado = rng
            End If
            strCamion = rdBuscar("NombreRuta").ToString.Trim
            For j = 2 To 16
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = rdBuscar("NoEonomico")
            wb.SHEETS(1).cells(rng, 3).value = rdBuscar("general")
            wb.SHEETS(1).cells(rng, 4).value = rdBuscar("general") * PrecioG
            wb.SHEETS(1).cells(rng, 5).value = rdBuscar("preferencial")
            wb.SHEETS(1).cells(rng, 6).value = rdBuscar("preferencial") * PrecioP
            wb.SHEETS(1).cells(rng, 7).value = rdBuscar("TotalBoletos")
            wb.SHEETS(1).cells(rng, 8).value = rdBuscar("Liquidacion")
            wb.SHEETS(1).cells(rng, 9).value = rdBuscar("general") + rdBuscar("preferencial") + rdBuscar("boletos")
            wb.SHEETS(1).cells(rng, 10).value = (rdBuscar("general") * PrecioG) + (rdBuscar("preferencial") * PrecioP) + rdBuscar("Liquidacion")
            wb.SHEETS(1).cells(rng, 11).value = rdBuscar("Vueltas")
            wb.SHEETS(1).cells(rng, 12).value = rdBuscar("Vueltas") * BuscarDblDatoCitra("Ruta", "Kilometros", "IdRuta=" & rdBuscar("IdRuta"))

            totalUG = totalUG + wb.SHEETS(1).cells(rng, 3).value
            totalIG = totalIG + wb.SHEETS(1).cells(rng, 4).value
            totalUP = totalUP + wb.SHEETS(1).cells(rng, 5).value
            totalIP = totalIP + wb.SHEETS(1).cells(rng, 6).value
            totalUB = totalUB + wb.SHEETS(1).cells(rng, 7).value
            totalIB = totalIB + wb.SHEETS(1).cells(rng, 8).value
            TotalV = TotalV + wb.SHEETS(1).cells(rng, 9).value
            TotalK = TotalK + wb.SHEETS(1).cells(rng, 10).value

            totalUGG = totalUGG + wb.SHEETS(1).cells(rng, 3).value
            totalIGG = totalIGG + wb.SHEETS(1).cells(rng, 4).value
            totalUPG = totalUPG + wb.SHEETS(1).cells(rng, 5).value
            totalIPG = totalIPG + wb.SHEETS(1).cells(rng, 6).value
            totalUBG = totalUBG + wb.SHEETS(1).cells(rng, 7).value
            totalIBG = totalIBG + wb.SHEETS(1).cells(rng, 8).value
            TotalVG = TotalVG + wb.SHEETS(1).cells(rng, 9).value
            TotalKG = TotalKG + wb.SHEETS(1).cells(rng, 10).value

            rng = rng + 1
            ' End If
        Loop
        For j = 2 To 16
            wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

        Next
        wb.SHEETS(1).cells(rng, 2).value = "Totales"
        wb.SHEETS(1).cells(rng, 3).value = totalUG
        wb.SHEETS(1).cells(rng, 4).value = totalIG
        wb.SHEETS(1).cells(rng, 5).value = totalUP
        wb.SHEETS(1).cells(rng, 6).value = totalIP
        wb.SHEETS(1).cells(rng, 7).value = totalUB
        wb.SHEETS(1).cells(rng, 8).value = totalIB
        wb.SHEETS(1).cells(rng, 9).value = totalUG + totalUP + totalUB
        wb.SHEETS(1).cells(rng, 10).value = totalIG + totalIP + totalIB
        wb.SHEETS(1).cells(rng, 11).value = TotalV
        wb.SHEETS(1).cells(rng, 12).value = TotalK
        wb.SHEETS(1).cells(rng, 13).value = wb.SHEETS(1).cells(rng, 8).value / TotalV
        wb.SHEETS(1).cells(rng, 14).value = wb.SHEETS(1).cells(rng, 9).value / TotalV
        wb.SHEETS(1).cells(rng, 15).value = wb.SHEETS(1).cells(rng, 8).value / TotalK
        wb.SHEETS(1).cells(rng, 16).value = wb.SHEETS(1).cells(rng, 9).value / TotalK

        For i = Encabezado To rng - 1
            wb.SHEETS(1).cells(i, 13).value = wb.SHEETS(1).cells(i, 9).value / wb.SHEETS(1).cells(i, 11).value
            wb.SHEETS(1).cells(i, 14).value = wb.SHEETS(1).cells(i, 10).value / wb.SHEETS(1).cells(i, 11).value
            wb.SHEETS(1).cells(i, 15).value = wb.SHEETS(1).cells(i, 9).value / wb.SHEETS(1).cells(i, 12).value
            wb.SHEETS(1).cells(i, 16).value = wb.SHEETS(1).cells(i, 10).value / wb.SHEETS(1).cells(i, 12).value
        Next

        For i = 2 To 16
            wb.SHEETS(1).cells(rng, i).font.italic = True
        Next
        rng = rng + 2
        For j = 2 To 16
            wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

        Next
        wb.SHEETS(1).cells(rng, 2).value = "Total General"
        wb.SHEETS(1).cells(rng, 3).value = totalUGG
        wb.SHEETS(1).cells(rng, 4).value = totalIGG
        wb.SHEETS(1).cells(rng, 5).value = totalUPG
        wb.SHEETS(1).cells(rng, 6).value = totalIPG
        wb.SHEETS(1).cells(rng, 7).value = totalUBG
        wb.SHEETS(1).cells(rng, 8).value = totalIBG
        wb.SHEETS(1).cells(rng, 9).value = totalUGG + totalUPG + totalUBG
        wb.SHEETS(1).cells(rng, 10).value = totalIGG + totalIPG + totalIBG
        wb.SHEETS(1).cells(rng, 11).value = TotalVG
        wb.SHEETS(1).cells(rng, 12).value = TotalKG
        For i = 2 To 12
            wb.SHEETS(1).cells(rng, i).font.italic = True
            wb.SHEETS(1).cells(rng, i).font.bold = True
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Reporte de Ingresos del " & Me.datFecha1.Value.ToString("d") & " al " & Me.datFecha2.Value.ToString("d")
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

    End Sub
    Sub TodosOperadores()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook
        Dim rng As Integer
        rng = 5

        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim strFecha1 As String = Format(Me.datFecha1.Value.Year, "0000") & Format(Me.datFecha1.Value.Month, "00") & Format(Me.datFecha1.Value.Day, "00")
        Dim strFecha2 As String = Format(Me.datFecha2.Value.Year, "0000") & Format(Me.datFecha2.Value.Month, "00") & Format(Me.datFecha2.Value.Day, "00")
        '--------
        Dim cnconn As New SqlConnection
        cnconn.ConnectionString = CitraConnection
        Dim strSql As String = ""
        cnconn.Open()
        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnconn

        strSql = " SELECT IdRuta,NombreRuta,NombreOperador,SUM(General) as general,SUM(Preferencial) as preferencial,SUM(TotalBoletos) as boletos,SUM(Liquidacion) as total,SUM(Vueltas) as vueltas " & _
                 " FROM Liquidacion" & _
                 " WHERE convert(varchar,fecha,101)>='" & strFecha1 & "'" & _
                 " AND convert(varchar,fecha,101)<='" & strFecha2 & "'" & _
                 " GROUP BY NombreOperador,IdRuta,NombreRuta " & _
                 " ORDER BY NombreRuta,NombreOperador"

        cmdBuscar.CommandText = strSql
        Dim rdBuscar As SqlDataReader
        rdBuscar = cmdBuscar.ExecuteReader
        Dim strFecha As String = ""
        Dim strCamion As String = "?"
        Dim strFechaMov As String = ""
        Dim PrecioP As Double = 3.7
        Dim PrecioG As Double = 6.3

        Dim totalUP As Double = 0
        Dim totalUG As Double = 0
        Dim totalUB As Double = 0
        Dim totalIP As Double = 0
        Dim totalIG As Double = 0
        Dim totalIB As Double = 0
        Dim TotalV As Double = 0
        Dim TotalK As Double = 0


        Dim totalUPG As Double = 0
        Dim totalUGG As Double = 0
        Dim totalUBG As Double = 0
        Dim totalIPG As Double = 0
        Dim totalIGG As Double = 0
        Dim totalIBG As Double = 0
        Dim TotalVG As Double = 0
        Dim TotalKG As Double = 0
        Dim Encabezado As Integer = 0



        wb.SHEETS(1).columns(2).columnwidth = 30
        wb.SHEETS(1).columns(3).columnwidth = 12
        wb.SHEETS(1).columns(4).columnwidth = 12
        wb.SHEETS(1).columns(5).columnwidth = 12
        wb.SHEETS(1).columns(6).columnwidth = 12
        wb.SHEETS(1).columns(7).columnwidth = 12
        wb.SHEETS(1).columns(8).columnwidth = 12
        wb.SHEETS(1).columns(9).columnwidth = 12
        wb.SHEETS(1).columns(10).columnwidth = 12
        wb.sheets(1).columns(11).columnwidth = 12
        wb.sheets(1).columns(12).columnwidth = 12
        wb.sheets(1).columns(13).columnwidth = 12
        wb.sheets(1).columns(14).columnwidth = 12
        wb.sheets(1).columns(15).columnwidth = 12
        wb.sheets(1).columns(16).columnwidth = 12

        wb.SHEETS(1).columns(3).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(4).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(5).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(6).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(7).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(8).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(9).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(10).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(11).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(12).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(13).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(14).NumberFormat = "#,##0.00"
        wb.SHEETS(1).columns(15).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(16).NumberFormat = "#,##0.00"

        Do While rdBuscar.Read()
            If strCamion <> rdBuscar("NombreRuta").ToString.Trim Then
                If strCamion <> "?" Then
                    For j = 2 To 16
                        wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

                    Next
                    wb.SHEETS(1).cells(rng, 2).value = "Totales"
                    wb.SHEETS(1).cells(rng, 3).value = totalUG
                    wb.SHEETS(1).cells(rng, 4).value = totalIG
                    wb.SHEETS(1).cells(rng, 5).value = totalUP
                    wb.SHEETS(1).cells(rng, 6).value = totalIP
                    wb.SHEETS(1).cells(rng, 7).value = totalUB
                    wb.SHEETS(1).cells(rng, 8).value = totalIB
                    wb.SHEETS(1).cells(rng, 9).value = totalUG + totalUP + totalUB
                    wb.SHEETS(1).cells(rng, 10).value = totalIG + totalIP + totalIB
                    wb.SHEETS(1).cells(rng, 11).value = TotalV
                    wb.SHEETS(1).cells(rng, 12).value = TotalK
                    wb.SHEETS(1).cells(rng, 13).value = wb.SHEETS(1).cells(rng, 8).value / TotalV
                    wb.SHEETS(1).cells(rng, 14).value = wb.SHEETS(1).cells(rng, 9).value / TotalV
                    wb.SHEETS(1).cells(rng, 15).value = wb.SHEETS(1).cells(rng, 8).value / TotalK
                    wb.SHEETS(1).cells(rng, 16).value = wb.SHEETS(1).cells(rng, 9).value / TotalK

                    For i = Encabezado To rng - 1
                        wb.SHEETS(1).cells(i, 13).value = wb.SHEETS(1).cells(i, 9).value / wb.SHEETS(1).cells(i, 11).value
                        wb.SHEETS(1).cells(i, 14).value = wb.SHEETS(1).cells(i, 10).value / wb.SHEETS(1).cells(i, 11).value
                        wb.SHEETS(1).cells(i, 15).value = wb.SHEETS(1).cells(i, 9).value / wb.SHEETS(1).cells(i, 12).value
                        wb.SHEETS(1).cells(i, 16).value = wb.SHEETS(1).cells(i, 10).value / wb.SHEETS(1).cells(i, 12).value
                    Next

                    For i = 2 To 16
                        wb.SHEETS(1).cells(rng, i).font.italic = True
                    Next

                    totalUP = 0
                    totalUG = 0
                    totalUB = 0
                    totalIP = 0
                    totalIG = 0
                    totalIB = 0
                    TotalV = 0
                    TotalK = 0
                    rng = rng + 2 ' Separa entre ruta
                End If
                For j = 2 To 16
                    wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

                Next
                wb.SHEETS(1).cells(rng, 2).value = rdBuscar("Nombre").ToString.Trim
                wb.SHEETS(1).cells(rng, 2).font.size = 12
                wb.SHEETS(1).cells(rng, 2).font.bold = -1
                rng = rng + 1
                For j = 2 To 16
                    wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

                Next
                wb.SHEETS(1).cells(rng, 2).value = "Nombre Operador"
                wb.SHEETS(1).cells(rng, 3).value = "Pagobus General en Unidades"
                wb.SHEETS(1).cells(rng, 4).value = "Pagobus Preferencial en unidades"
                wb.SHEETS(1).cells(rng, 5).value = "Boletos en Unidades"
                wb.SHEETS(1).cells(rng, 6).value = "Pagobus General en Importes"
                wb.SHEETS(1).cells(rng, 7).value = "Pagobus Preferencial en Importes"
                wb.SHEETS(1).cells(rng, 8).value = "Boletos en Importes"
                wb.SHEETS(1).cells(rng, 9).value = "Movilidad en Unidades"
                wb.SHEETS(1).cells(rng, 10).value = "Movilidad en Pesos"
                wb.SHEETS(1).cells(rng, 11).value = "Vueltas"
                wb.SHEETS(1).cells(rng, 12).value = "Kilometros"
                wb.SHEETS(1).cells(rng, 13).value = "Promedio Movilidad por Vuelta"
                wb.SHEETS(1).cells(rng, 14).value = "Promedio Ingresos por Vuelta"
                wb.SHEETS(1).cells(rng, 15).value = "Promedio Movilidad por KM"
                wb.SHEETS(1).cells(rng, 16).value = "Promedio Ingresos por KM"

                For i = 2 To 16
                    wb.SHEETS(1).cells(rng, i).font.bold = True
                    wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
                    wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
                    wb.SHEETS(1).CELLS(rng, i).WrapText = True
                    wb.SHEETS(1).CELLS(rng, i).Orientation = 0
                    wb.SHEETS(1).CELLS(rng, i).AddIndent = False
                    wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
                    wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
                    wb.SHEETS(1).CELLS(rng, i).MergeCells = False
                    wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
                Next
                rng = rng + 1
                Encabezado = rng
            End If
            strCamion = rdBuscar("NombreRuta").ToString.Trim
            For j = 2 To 16
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = rdBuscar("NombreOperador")
            wb.SHEETS(1).cells(rng, 3).value = rdBuscar("general")
            wb.SHEETS(1).cells(rng, 4).value = rdBuscar("general") * PrecioG
            wb.SHEETS(1).cells(rng, 5).value = rdBuscar("preferencial")
            wb.SHEETS(1).cells(rng, 6).value = rdBuscar("preferencial") * PrecioP
            wb.SHEETS(1).cells(rng, 7).value = rdBuscar("TotalBoletos")
            wb.SHEETS(1).cells(rng, 8).value = rdBuscar("Liquidacion")
            wb.SHEETS(1).cells(rng, 9).value = rdBuscar("general") + rdBuscar("preferencial") + rdBuscar("boletos")
            wb.SHEETS(1).cells(rng, 10).value = (rdBuscar("general") * PrecioG) + (rdBuscar("preferencial") * PrecioP) + rdBuscar("Liquidacion")
            wb.SHEETS(1).cells(rng, 11).value = rdBuscar("Vueltas")
            wb.SHEETS(1).cells(rng, 12).value = rdBuscar("Vueltas") * BuscarDblDatoCitra("Ruta", "Kilometros", "IdRuta=" & rdBuscar("IdRuta"))

            totalUG = totalUG + wb.SHEETS(1).cells(rng, 3).value
            totalIG = totalIG + wb.SHEETS(1).cells(rng, 4).value
            totalUP = totalUP + wb.SHEETS(1).cells(rng, 5).value
            totalIP = totalIP + wb.SHEETS(1).cells(rng, 6).value
            totalUB = totalUB + wb.SHEETS(1).cells(rng, 7).value
            totalIB = totalIB + wb.SHEETS(1).cells(rng, 8).value
            TotalV = TotalV + wb.SHEETS(1).cells(rng, 9).value
            TotalK = TotalK + wb.SHEETS(1).cells(rng, 10).value

            totalUGG = totalUGG + wb.SHEETS(1).cells(rng, 3).value
            totalIGG = totalIGG + wb.SHEETS(1).cells(rng, 4).value
            totalUPG = totalUPG + wb.SHEETS(1).cells(rng, 5).value
            totalIPG = totalIPG + wb.SHEETS(1).cells(rng, 6).value
            totalUBG = totalUBG + wb.SHEETS(1).cells(rng, 7).value
            totalIBG = totalIBG + wb.SHEETS(1).cells(rng, 8).value
            TotalVG = TotalVG + wb.SHEETS(1).cells(rng, 9).value
            TotalKG = TotalKG + wb.SHEETS(1).cells(rng, 10).value

            rng = rng + 1
            ' End If
        Loop
        For j = 2 To 16
            wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

        Next
        wb.SHEETS(1).cells(rng, 2).value = "Totales"
        wb.SHEETS(1).cells(rng, 3).value = totalUG
        wb.SHEETS(1).cells(rng, 4).value = totalIG
        wb.SHEETS(1).cells(rng, 5).value = totalUP
        wb.SHEETS(1).cells(rng, 6).value = totalIP
        wb.SHEETS(1).cells(rng, 7).value = totalUB
        wb.SHEETS(1).cells(rng, 8).value = totalIB
        wb.SHEETS(1).cells(rng, 9).value = totalUG + totalUP + totalUB
        wb.SHEETS(1).cells(rng, 10).value = totalIG + totalIP + totalIB
        wb.SHEETS(1).cells(rng, 11).value = TotalV
        wb.SHEETS(1).cells(rng, 12).value = TotalK
        wb.SHEETS(1).cells(rng, 13).value = wb.SHEETS(1).cells(rng, 8).value / TotalV
        wb.SHEETS(1).cells(rng, 14).value = wb.SHEETS(1).cells(rng, 9).value / TotalV
        wb.SHEETS(1).cells(rng, 15).value = wb.SHEETS(1).cells(rng, 8).value / TotalK
        wb.SHEETS(1).cells(rng, 16).value = wb.SHEETS(1).cells(rng, 9).value / TotalK

        For i = Encabezado To rng - 1
            wb.SHEETS(1).cells(i, 13).value = wb.SHEETS(1).cells(i, 9).value / wb.SHEETS(1).cells(i, 11).value
            wb.SHEETS(1).cells(i, 14).value = wb.SHEETS(1).cells(i, 10).value / wb.SHEETS(1).cells(i, 11).value
            wb.SHEETS(1).cells(i, 15).value = wb.SHEETS(1).cells(i, 9).value / wb.SHEETS(1).cells(i, 12).value
            wb.SHEETS(1).cells(i, 16).value = wb.SHEETS(1).cells(i, 10).value / wb.SHEETS(1).cells(i, 12).value
        Next

        For i = 2 To 16
            wb.SHEETS(1).cells(rng, i).font.italic = True
        Next
        rng = rng + 2
        For j = 2 To 16
            wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

        Next
        wb.SHEETS(1).cells(rng, 2).value = "Total General"
        wb.SHEETS(1).cells(rng, 3).value = totalUGG
        wb.SHEETS(1).cells(rng, 4).value = totalIGG
        wb.SHEETS(1).cells(rng, 5).value = totalUPG
        wb.SHEETS(1).cells(rng, 6).value = totalIPG
        wb.SHEETS(1).cells(rng, 7).value = totalUBG
        wb.SHEETS(1).cells(rng, 8).value = totalIBG
        wb.SHEETS(1).cells(rng, 9).value = totalUGG + totalUPG + totalUBG
        wb.SHEETS(1).cells(rng, 10).value = totalIGG + totalIPG + totalIBG
        wb.SHEETS(1).cells(rng, 11).value = TotalVG
        wb.SHEETS(1).cells(rng, 12).value = TotalKG
        For i = 2 To 12
            wb.SHEETS(1).cells(rng, i).font.italic = True
            wb.SHEETS(1).cells(rng, i).font.bold = True
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Reporte de Ingresos del " & Me.datFecha1.Value.ToString("d") & " al " & Me.datFecha2.Value.ToString("d")
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"
    End Sub

    Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click
        If RadioButton1.Checked = True Then
            todos()
            Bitacora.RegistraActividad("Imprimió al Reporte de Ingresos acumulado por Autobus")
        ElseIf RadioButton2.Checked = True Then
            TodosOperadores()
            Bitacora.RegistraActividad("Imprimió al Reporte de Ingresos acumulado por Operador")
        End If
    End Sub
End Class